#!/bin/bash

PHP_VERSION=php-5.6.9
PHP_FPM_PORT=9056
PHP_ALIAS=php56

yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

####查询nginx用户是否存在####
user=nginx 
group=nginx

#create group if not exists  
egrep "^$group" /etc/group >& /dev/null  
if [ $? -ne 0 ]  
then  
    groupadd -r -g 80 $group  
fi  

#create user if not exists  
egrep "^$user" /etc/passwd >& /dev/null  
if [ $? -ne 0 ]  
then  
    useradd -r -u 80 -g 80 -M -s /sbin/nologin $user  
fi  
#### end created user - nginx

tar xf ${PHP_VERSION}.tar.gz

 cd ${PHP_VERSION}

./configure \
--prefix=/usr/local/${PHP_ALIAS} \
--with-config-file-path=/usr/local/${PHP_ALIAS}/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache

make && make install

cp php.ini-production /usr/local/${PHP_ALIAS}/etc/php.ini
cp /usr/local/${PHP_ALIAS}/etc/php-fpm.conf.default /usr/local/${PHP_ALIAS}/etc/php-fpm.conf

# 切换php-fpm端口
sed "s/9000/${PHP_FPM_PORT}/g" /usr/local/${PHP_ALIAS}/etc/php-fpm.conf.default > /usr/local/${PHP_ALIAS}/etc/php-fpm.conf

# init.d
cp sapi/fpm/init.d.php-fpm /etc/init.d/${PHP_ALIAS}-fpm
chmod +x /etc/init.d/${PHP_ALIAS}-fpm


# 启动php-fpm
/etc/init.d/${PHP_ALIAS}-fpm start


# cp -r test  /var/www/

# rm -rf /var/www/test/*.conf

# 配置nginx